package com.quzi.kettle.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

public class DialogUtil {
	private static volatile ProgressDialog progressDialog;

	public static void showErrorToast(Context ctx, String errorMsg) {
		Toast errorToast = Toast.makeText(ctx, errorMsg, Toast.LENGTH_LONG);
		errorToast.setGravity(Gravity.CENTER, 0, 0);
		errorToast.show();
	}

	public static void showProgressDialog(Context context) {
		showProgressDialog(context, "正在处理");

	}

//	public static boolean getIsShowing() {
//		if (progressDialog != null) {
//			return progressDialog.isShowing();
//		} else {
//			return false;
//		}
//
//	}

	public static void showProgressDialog(Context context, String msg) {
		synchronized (DialogUtil.class) {

			progressDialog = new ProgressDialog(context);
			progressDialog.setCanceledOnTouchOutside(false);
			progressDialog.setCancelable(false);
			progressDialog.setMessage(msg);
			try {
				progressDialog.show();
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
	}

	public static void hideProgressDialog() {
		synchronized (DialogUtil.class) {
			if (progressDialog != null && progressDialog.isShowing()) {
				progressDialog.hide();
			}
		}
	}

}